package com.itboye.textileexpres.base;

import com.android.volley.ServerError;
import com.itboye.core.interfaces.ICompleteListener;
import com.itboye.core.interfaces.XErrorListener;

public class BaseErrorListener implements XErrorListener {
	
	private ICompleteListener listener;
	public BaseErrorListener(ICompleteListener listener){
		this.listener = listener;
	}
	
	@Override
	public void onErrorResponse(Exception exception, String code, String msg) {
			
		if(listener != null){
				
			if(code == "0"){
					code = "-199";
			}
			if(msg == null || msg.isEmpty()){
				if(exception != null){
					msg = exception.getMessage();
				}else{
					msg = "发生未知错误!";
				}
			}
			if(exception instanceof ServerError){
				ServerError error = (ServerError) exception;
				code = ""+ error.networkResponse.statusCode;
				msg = "服务器返回错误!";
				
			}
				
			ResultEntity result = new ResultEntity(code,msg, exception);
			listener.failure(result);
		}				
	}
}

